# Makefile for NETCONF project
#  
#   NCX agent main directory

############### SOURCE PROFILE ##############################

SUBDIR_NM=agt
SUBDIR_CPP=

############### TARGET PROFILE ##############################

TARGET=$(TBASE)/$(SUBDIR_NM)
BIN_INST=$(TBASE)/bin

LIB_INST=$(TBASE)/lib

ifdef FREEBSD
REAL_INST=$(DESTDIR)$(PREFIX)/lib
else
ifdef LIB64
REAL_INST=$(DESTDIR)$(PREFIX)/lib64
else
REAL_INST=$(DESTDIR)$(PREFIX)/lib
endif
endif

# if the target is DEBIAN or RPM package, then
# install the include files
REAL_INC_INST=$(DESTDIR)$(PREFIX)/include/yuma

#################### MAKE RULES ########################
ifdef DEVELOPER
all:
else
all: agtdummy agtlib
endif  # DEVELOPER

#################### PLATFORM DEFINITIONS ############
include ../platform/platform.profile

################ DEPENDENCIES #########################
# depend rule must be included after the 'all' make rule

include ../platform/platform.profile.depend

ifdef DEBIAN
BLD_INCLUDES=
else
BLD_INCLUDES=includes
endif

test:

# build the library in any developer context
# and in the 1-pass RPM RELEASE build
# for ubunte RELEASE builds, only build if 
# this is the yuma package (not DEVELOPER)

ifdef DEVELOPER
# just install the H files
install: includes
else
ifdef CROSS_TARGET
# don't install anything
install:
else
# normal build: 'make' or 'make STATIC=1'
install: $(BLD_INCLUDES)
# install static or dynamic libagt file
	mkdir -p $(REAL_INST)
	install -v $(OWNER) $(GRP) \
	$(LIB_INST)/lib$(SUBDIR_NM).$(LIBNCXSUFFIX) $(REAL_INST)
ifndef STATIC
# libagt.so --> libagt.so.M.N
# libagt.so.1 --> libagt.so.M.N
#ifndef MAC
#ifdef DEBIAN
#ifdef DEVELOPER
#	(cd $(REAL_INST); \
#	ln -f -s lib$(SUBDIR_NM).$(LIBNCXSUFFIX) \
#	lib$(SUBDIR_NM).$(LIBSUFFIX);\
#	ln -f -s lib$(SUBDIR_NM).$(LIBNCXSUFFIX) \
#	lib$(SUBDIR_NM).$(LIBSUFFIX).$(LIBNCX_MAJOR_VERSION))
#endif  # DEVELOPER
#else
#	(cd $(REAL_INST); \
#	ln -f -s lib$(SUBDIR_NM).$(LIBNCXSUFFIX) \
#	lib$(SUBDIR_NM).$(LIBSUFFIX);\
#	ln -f -s lib$(SUBDIR_NM).$(LIBNCXSUFFIX) \
#	lib$(SUBDIR_NM).$(LIBSUFFIX).$(LIBNCX_MAJOR_VERSION))
#endif  # DEBIAN
#endif  # MAC
ifndef FREEBSD
ifndef DESTDIR
ifndef MAC
# skip in MacOsX, RPM, FreeBSD and rest of debian fakeroot builds
	ldconfig $(REAL_INST)
endif  # MAC
endif  # DESTDIR
endif  # FREEBSD
endif  # STATIC
endif  # CROSS_TARGET
endif  # DEVELOPER


uninstall:
	rm -f $(REAL_INST)/lib$(SUBDIR_NM).$(LIBSUFFIX)*


# check which variant of the library to build
ifdef DEVELOPER
agtlib:
else
agtlib: $(LBASE)/lib$(SUBDIR_NM).$(LIBNCXSUFFIX)
ifndef STATIC
ifndef MAC
	(cd $(LBASE); ln -f -s lib$(SUBDIR_NM).$(LIBNCXSUFFIX) \
	lib$(SUBDIR_NM).$(LIBSUFFIX))
endif  # MAC
endif  # STATIC
endif  # DEVELOPER


# this dummy rule keeps make from deleting the $(OBJS) as
# intermediate files
agtdummy: dependencies $(OBJS)

clean:
	rm -f $(OBJS) $(LBASE)/lib$(SUBDIR_NM).*


superclean:
	rm -f *~  $(DEPS) dependencies $(OBJS) \
	$(LBASE)/lib$(SUBDIR_NM).*

distclean: superclean


ifdef WINDOWS
RDYNAMIC=
LC=
else
RDYNAMIC=-rdynamic
LC=-lc
endif

# this rule is ignored if STATIC=1; used only in linux
$(LBASE)/libagt.so.$(SOVERSION): $(OBJS)
ifdef FREEBSD
	$(CC) $(CFLAGS) -shared $(RDYNAMIC) -Wl,-soname,libagt.so.$(SOVERSION) \
	-o $@ $(OBJS) -L/usr/local/lib $(LC) -lxml2
else
	$(CC) $(CFLAGS) -shared $(RDYNAMIC) -Wl,-soname,libagt.so.$(SOVERSION) \
	-o $@ $(OBJS) $(LC) -lxml2
endif

# this rule is ignored if STATIC=1; used only on MacOSX
$(LBASE)/libagt.dylib: $(OBJS)
	$(CC) $(CFLAGS) -shared -dynamiclib -std=gnu99 -current_version \
	$(SOVERSION) \
	-undefined dynamic_lookup \
	-o $@ -install_name libagt.dylib $(OBJS) -lxml2


includes:
	mkdir -p $(REAL_INC_INST)/agt
	cp *.h $(REAL_INC_INST)/agt


.PHONY: includes agtlib agtdummy


# prevent the make program from choking on all the symbols
# that get generated from autogenerated make rules
.NOEXPORT:

ifndef CLIENT
ifndef DEVELOPER
include dependencies
endif
endif
